package charts; 
import charts.elements.Element;
import charts.elements.PointBarCandle;
import string.Utils;

class BarCandle extends BarBase<StyleStruct, PointBarCandle> {
	//private var line_width:Float;
	//private var line_width:Float;
	
	public function new( lv:Array<Dynamic>, num:Float, group:Float ) {
		super( lv, num, group, 'candle' );
	}
	
	public override function parse_bar( val:Dynamic ):Void {
		var vals:Array<Dynamic> = val.split(",");
	
		//this.alpha = Float( vals[0] );
		this.line_width = Std.parseFloat( vals[1] ); // TODO - Counter check syntax
		this.colour = Utils.get_colour(vals[2]);
		
		if( vals.length > 3 )
			this.key =  StringTools.replace(vals[3],'#comma#',',');
			
		if( vals.length > 4 )
			this.font_size = Std.parseFloat( vals[4] );
	}

	//
	// the data looks like "[1,2,3,4],[2,3,4,5]"
	// this returns an array of strings like '1,2,3,4','2,3,4,5'
	// these are then parsed further in PointBarCandle
	//
	override function parse_list( values:String ):Array<Dynamic> {
		var groups:Array<Dynamic>=new Array();
		var tmp:String = '';
		var start:Bool = false;

		for( i in 0...values.length)
		{
			switch( values.charAt(i) )
			{
				case '[':
					start=true;
					break;
				case ']':
					start = false;
					groups.push( tmp );
					tmp = '';
					break;
				default:
					if( start )
						tmp += values.charAt(i);
					break;
			}
		}
		return groups;
	}
	
	
	//
	// called from the base object
	//
	override function get_element( x:Float, value:Dynamic ): PointBarCandle {
		return new PointBarCandle( x, value, this.line_width, this.colour, this.group );
	}
}
